package com.empi.storage;

import com.obs.services.ObsClient;
import com.obs.services.model.ListBucketsRequest;
import com.obs.services.model.ObsBucket;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController("/")
public class DemoController {

    @RequestMapping("/test")
    public String test(){
        try {
            String endPoint = "http://11.125.1.249";
            String ak = "6WNRCBYLMT5OLYHOYWNC";
            String sk = "QhSbEwDgGG1liQlEyCM5emC4AqflgzndutSbKMnD";
// 创建ObsClient实例
            ObsClient obsClient = new ObsClient(ak, sk, endPoint);
// 列举桶
            ListBucketsRequest request = new ListBucketsRequest();
            request.setQueryLocation(true);
            List<ObsBucket> buckets = obsClient.listBuckets(request);
            for(ObsBucket bucket : buckets)
            {
                System.out.println("BucketName:" + bucket.getBucketName());
                System.out.println("CreationDate:" + bucket.getCreationDate());
                System.out.println("Location:" + bucket.getLocation());
            }
// 关闭obsClient
            obsClient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "test";
    }
}
